package fpt.edu.vn.action;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import fpt.edu.vn.dao.TopicsDao;
import fpt.edu.vn.model.Activityhistorys;

/* 
 * DetailAction.java 
 *  
 * 0.1
 * 
 * 10/15/2012 
 *  
 * Copyright notice 
 *  
 * Modification Logs: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  -------------------------------------------------------- 
 *  15-Oct-2012  ThuongND    Create new 
 */
public class LogoutAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private TopicsDao dao = new TopicsDao();
	private Activityhistorys activityhistory = new Activityhistorys();
	private String isLogout;

	// For SessionAware
	public String execute() {
		String ipaddress = "";
		Map<String, Object> session = ActionContext.getContext().getSession();
		// if("1".equals(isLogout)){

		if (session.containsKey("ipaddress")) {
			ipaddress = (String) session.get("ipaddress");
		}
		String email = "";
		email = (String) session.get("emailss");
		activityhistory.setActivityTypeId(3);
		activityhistory.setIpAddress(ipaddress);
		activityhistory.setUserName(email);
		dao.add(activityhistory);

		session.remove("displayNamess");
		session.remove("emailss");

		// }
		((org.apache.struts2.dispatcher.SessionMap) ActionContext.getContext()
				.getSession()).invalidate();

		return SUCCESS;
	}

	public Activityhistorys getActivityhistory() {
		return activityhistory;
	}

	public void setActivityhistory(Activityhistorys activityhistory) {
		this.activityhistory = activityhistory;
	}

}
